<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<div class="center_content">
    <div class="center_title_bar">Add Product </div>
    <div class="prod_box_big">
        <div class="top_prod_box_big"></div>
        <div class="center_prod_box_big">
            <div class="contact_form">
                <form action="addProduct" method="post" name="myform" id="myform" >
                    <div class="form_row">
                        <div id='myform_bname_errorloc' class="error_strings"></div>
                        <label class="contact"><strong>Book Name:</strong></label>
                        <input type="text" class="contact_input" name="bname"/>
                    </div>
                    <sql:setDataSource driver="com.mysql.jdbc.Driver"
                                       url="jdbc:mysql://localhost/Commerce"
                                       user="root"  password="root"/>
                    <sql:query var="users">
                        SELECT cat_name from category;
                    </sql:query>
                    <div class="form_row">
                        <label class="contact"><strong>Book Cat :</strong></label>
                        <select name="bcat">
                            <c:forEach items="${users.rows}" var="row">
                                <option value="<c:out value="${row.cat_name}"/> ">${row.cat_name}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="form_row">
                        <div id='myform_price_errorloc' class="error_strings"></div>
                        <label class="contact"><strong>Price:</strong></label>
                        <input type="text" class="contact_input" name="price"/>
                    </div>
                    <div class="form_row">
                        <div id='myform_quantity_errorloc' class="error_strings"></div>
                        <label class="contact"><strong> Quantity :</strong></label>
                        <input type="text" class="contact_input" name="quantity"/>
                    </div>
                    <div class="form_row">
                        <div id='myform_img_errorloc' class="error_strings"></div>
                        <label class="contact"><strong>Image:</strong></label>
                        <input type="file" class="contact_input" name="img"/>
                    </div>
                    <div class="form_row"> <input type="submit" value="Add Book" id="signupbtn">
                    </div>
                </form>
            </div>
        </div>
        <div class="bottom_prod_box_big"></div>
    </div>
</div>
<script language="JavaScript" type="text/javascript">//<![CDATA[
//You should create the validator only after the definition of the HTML form
    var frmvalidator = new Validator("myform");
    frmvalidator.EnableOnPageErrorDisplay();
    frmvalidator.EnableMsgsTogether();

    frmvalidator.addValidation("bname", "req", "Please enter your First Name");
    frmvalidator.addValidation("bname", "alpha_s", "First Name can contain alphabetic chars only");

    frmvalidator.addValidation("price", "req", "Please enter price");
    frmvalidator.addValidation("price", "numeric");
    frmvalidator.addValidation("price", "gtelmnt=2", "Credite Balance  should be larger than 2 numbers");

    frmvalidator.addValidation("quantity", "req", "Please enter price");
    frmvalidator.addValidation("quantity", "numeric");
    
    frmvalidator.addValidation("img", "file_extn=jpg;gif;png;jpeg", "Allowed files types are: jpg;gif;png");
    frmvalidator.addValidation("img", "req_file", "File upload is required");
//]]></script>